/*
    Copyright 2009 Spencer B. Koehler, Ph.D.

    This file is part of the Brillig Toolkit.

    The Brillig Toolkit is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Brillig Toolkit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with The Brillig Toolkit.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.brillig.text;


import org.brillig.util.logic.LogicalResult;
import org.brillig.util.logic.TruthFunction;

/**
 * A TruthFunction (used with the logic package's LogicalExpression class)
 * for input strings containing terms according to a term finder.
 * <p>
 * @author Spence Koehler
 */
public class TermFinderTruthFunction extends TruthFunction<String> {

  private TermFinder termFinder;
  private int acceptPartial;

  public TermFinderTruthFunction(boolean caseSensitive, String[] terms, int acceptPartial) {
    this(new TermFinder("", caseSensitive, terms), acceptPartial);
  }

  public TermFinderTruthFunction(TermFinder termFinder, int acceptPartial) {
    this.termFinder = termFinder;
    this.acceptPartial = acceptPartial;
  }

  public TermFinder getTermFinder() {
    return termFinder;
  }

  public int getAcceptPartial() {
    return acceptPartial;
  }

  public LogicalResult<String> evaluateInput(String input) {
    return new TermFinderLogicalResult(input, termFinder.findPatternPos(input, acceptPartial), this);
  }
}
